<%--
    Document   : header
    Created on : 25/11/2013, 16:13:18
    Author     : Reno
--%>

<%@page import="javax.swing.JOptionPane"%>
<%@page import="adocao.OracleConnector"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>

<img class="logo" src="_res/images/logo.png">
    <%if(request.getParameter("usuario")!= null){
        String user = request.getParameter("usuario");
        String pass = request.getParameter("senha");
        String SQL = "SELECT * FROM login_senha WHERE nm_login='"+user+"' AND nm_senha='"+pass+"'";
        if (OracleConnector.getQuery(SQL).size()>0){
            session.setAttribute("usuario",request.getParameter("usuario"));
            response.sendRedirect(request.getContextPath());
        }else{
            out.println("<span style='color:red;'>Usuário e/ou senha inválida(s)!</span>");
        }
    }else if(request.getParameter("logoff")!= null){
        session.removeAttribute("usuario");
        response.sendRedirect(request.getContextPath());
    }
    if(session.getAttribute("usuario")== null){%>
        <form action="index.jsp" method="get" >
            <table>
            <tr>Usuário: <input type="text" name="usuario"/>
            Senha: <input type="password" name="senha"/>
            <input type="submit" value="Entrar"/>
            </table>
        </form>
    <% }else {%>
            Bem vindo, ${sessionScope.usuario} [<a href="?logoff">sair</a>]
    <%}%>
<hr/>